package mysql

import (
	"gorm.io/gorm"
)

type Goods struct {
	gorm.Model
	UserId     int     `gorm:"type:int;not null;comment:'用户Id'"`
	GoodsTitle string  `gorm:"type:varchar(100);index;not null;comment:'商品标题'"`
	GoodsPrice float64 `gorm:"type:double(10,2);not null;comment:'商品价格'"`
	GoodsCover string  `gorm:"type:varchar(255);not null;comment:'商品封面'"`
	GoodsStock int     `gorm:"type:int;comment:'商品库存'"`
	LikeCount  int     `gorm:"type:int;comment:'点赞量'"`
}

type User struct {
	gorm.Model
	Phone    string `gorm:"type:char(11);not null;comment:'手机号'"`
	Password string `gorm:"type:char(32);not null;comment:'密码'"`
}

func (u *User) Create() error {
	return DB.Create(&u).Error
}
func (u *User) GetCreate(phone string) error {
	return DB.Where("phone = ?", phone).Limit(1).Find(&u).Error
}

func (g *Goods) List(page, pageSize int) (list []*Goods, err2 error) {
	err = DB.Offset((page - 1) * pageSize).Limit(pageSize).Find(&list).Error
	return
}

func (g *Goods) Show(goodId int) error {
	return DB.Find(&g, goodId).Error
}
